using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BlogEngine.Core.Providers;
using BlogEngine.Core;

public partial class gallery_addalbum : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		Page.Title = Resources.labels.photos;

		btnAlbum.Click += new EventHandler(btnAlbum_Click);

		valExist.ServerValidate += new ServerValidateEventHandler(valExist_ServerValidate);
	}

	#region Event handlers

	private void valExist_ServerValidate(object source, ServerValidateEventArgs args)
	{
		args.IsValid = true;

		foreach (Album album in Album.Items)
			if (album.Title.Equals(txtTitle.Text.Trim(), StringComparison.OrdinalIgnoreCase))
				args.IsValid = false;
	}

	/// <summary>
	/// Creates and saves a new album
	/// </summary>
	private void btnAlbum_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
			if (txtTitle.Text.Trim().Length != 0)
			{
				Album album = new Album(txtTitle.Text, txtTitle.Text, txtDescription.Text);
				album.IsPublished = cbIsPublished.Checked;
				album.TagString = txtTags.Text;
				album.Save();
				txtTitle.Text = "";
				// TODO: redirect to add photos page
			}
	}


	#endregion

	#region Data Binding

	#endregion


}
